/**
 * Created with IntelliJ IDEA.
 * Description: leetcode.简单题.面试题.珠玑妙算
 */

class Solution {
    public int[] masterMind(String solution, String guess) {
        int[] num1 = new int[4];
        int[] num2 = new int[4];
        int[] answer = new int[2];
        int count = 0;
        for(int i = 0; i < 4; i++) {
            switch(solution.charAt(i)) {
                case 'R' :
                    num1[0]++;
                    break;
                case 'Y' :
                    num1[1]++;
                    break;
                case 'G' :
                    num1[2]++;
                    break;
                case 'B' :
                    num1[3]++;
                    break;
            }
        }

        for(int i = 0; i < 4; i++) {
            switch(guess.charAt(i)) {
                case 'R' :
                    num2[0]++;
                    break;
                case 'Y' :
                    num2[1]++;
                    break;
                case 'G' :
                    num2[2]++;
                    break;
                case 'B' :
                    num2[3]++;
                    break;
            }
        }

        for(int i = 0; i < 4; i++) {
            num1[i] = num1[i] < num2[i] ? num1[i] : num2[i];
        }

        for(int i = 0; i < 4; i++) {
            if(solution.charAt(i) == guess.charAt(i)){
                count++;
                switch(guess.charAt(i)) {
                    case 'R' :
                        num1[0]--;
                        break;
                    case 'Y' :
                        num1[1]--;
                        break;
                    case 'G' :
                        num1[2]--;
                        break;
                    case 'B' :
                        num1[3]--;
                        break;
                }
            }
        }
        answer[0] = count;
        for(int i = 0; i < 4; i++) {
            answer[1] += num1[i];
        }
        return answer;
    }
}

public class Test {
    public static void main(String[] args) {
        Solution s = new Solution();
        int[] num = s.masterMind("RGBY","GGRR");
    }
}
